home *** CD-ROM | disk | FTP | other *** search
/ CDV Software Presents (USA) / CDV Software Presents (USA).bin / demo / bk_demo.exe / DATA.PAK / ui / mission_buttons.lua < prev    next >
Encoding:
Text File  |  2002-12-26  |  18.4 KB  |  738 lines

  1. nLastActiveButton = 0
  2. p1 = 0
  3. p2 = 0
  4. p3 = 0
  5. p4 = 0            --priority of bottom row buttons
  6.  
  7. --p1:   SUPPRESS 40, DEPLOY ARTILLERY 35, UNLOAD 30, BUILD 20, FORMATION 10
  8. --p2:    RANGING 40, RESUPPLY 30, REPAIR 20, BINOCULARS 10
  9. --p3:    SHELL TYPE 40, MOBILIZE 30, SET MINE 20, SQUAD- 10, SQUAD+ 5
  10. --p4:    DEMINE 20
  11.  
  12. gActiveFormations = { 0, 0, 0, 0, 0 }
  13. gActiveAviations = { 0, 0, 0, 0, 0 }
  14. gActiveShellTypes = { 0, 0, 0, }    --DAMAGE, AGITATION, SMOKE
  15.  
  16. gButtons = {
  17.     {  1, 63, 17,  2,  3,  6, 10, 16, -1, -1, -1, -1 },        --USUAL
  18.     { 23, 29, 24, 28, -1, -1, -1, -1, -1, -1, -1,  0 },        --BUILD
  19.     { 20, 21, -1, -1, -1, -1, -1, -1, -1, -1, -1,  0 },        --MINE
  20.     { 50, 53, 52, 51, 54, -1, -1, -1, -1, -1, -1,  0 },        --FORMATION
  21.     { 32, 30, 31, 35, 33, -1, -1, -1, -1, -1, -1,  0 },        --AVIA
  22. --    { 55, 56, 57, -1, -1, -1, -1, -1, -1, -1, -1,  0 },        --CHOOSE SHELL TYPE
  23.     { 55, 57, -1, -1, -1, -1, -1, -1, -1, -1, -1,  0 },        --CHOOSE SHELL TYPE  without morale shell
  24. }
  25.  
  26. E_USUAL_BUTTONS            = 1
  27. E_BUILD_BUTTONS            = 2
  28. E_MINE_BUTTONS            = 3
  29. E_FORMATION_BUTTONS        = 4
  30. E_AVIA_BUTTONS            = 5
  31. E_SHELL_BUTTONS            = 6
  32. nActivePanel = E_USUAL_BUTTONS
  33.  
  34. function LuaLoad( ... )
  35.     local i = 1
  36.     if ( arg.n < 10 ) then
  37.         CallNullScriptError()        --THERE IS NO SUCH FUNCTION
  38.         return
  39.     end
  40.  
  41.     while ( i <= 5 ) do
  42.         gActiveFormations[i] = arg[i*2]
  43.         i = i + 1
  44.     end
  45.  
  46.     while ( i <= 10 ) do
  47.         gActiveAviations[i - 5] = arg[i*2]
  48.         i = i + 1
  49.     end
  50.  
  51.     nActivePanel = arg[22]
  52.     nLastActiveButton = arg[24]
  53.     gButtons[1][9] = arg[26]
  54.     gButtons[1][10] = arg[28]
  55.     gButtons[1][11] = arg[30]
  56.     gButtons[1][12] = arg[32]
  57.  
  58.     gActiveShellTypes[1] = arg[34]
  59.     gActiveShellTypes[2] = arg[36]
  60.     gActiveShellTypes[3] = arg[38]
  61. end
  62.  
  63. function LuaSave()
  64.     local i = 1
  65.     while ( i <= 5 ) do
  66.         SaveLuaValue( i, gActiveFormations[i] )
  67.         i = i + 1
  68.     end
  69.  
  70.     while ( i <= 10 ) do
  71.         SaveLuaValue( i, gActiveAviations[i - 5] )
  72.         i = i + 1
  73.     end
  74.  
  75.     SaveLuaValue( 11, nActivePanel )
  76.     SaveLuaValue( 12, nLastActiveButton )
  77.     SaveLuaValue( 13, gButtons[1][9] )
  78.     SaveLuaValue( 14, gButtons[1][10] )
  79.     SaveLuaValue( 15, gButtons[1][11] )
  80.     SaveLuaValue( 16, gButtons[1][12] )
  81.  
  82.     SaveLuaValue( 17, gActiveShellTypes[1] )
  83.     SaveLuaValue( 18, gActiveShellTypes[2] )
  84.     SaveLuaValue( 19, gActiveShellTypes[3] )
  85. end
  86.  
  87. function IsActiveButton( nIndex )
  88.     if ( nIndex == 1 or nIndex == 2 or nIndex == 3 ) then
  89.         return 1
  90.     end
  91.  
  92.     if ( nIndex == 5 or nIndex == 6 ) then
  93.         return 1
  94.     end
  95.  
  96.     if ( nIndex == 10 or nIndex == 12 or nIndex == 13 or nIndex == 16 or nIndex == 17 ) then
  97.         return 1
  98.     end
  99.  
  100.     if ( nIndex == 22 or nIndex == 26 or nIndex == 27 or nIndex == 34 or nIndex == 36) then
  101.         return 1
  102.     end
  103.  
  104.     if ( nIndex == 42 or nIndex == 61 or nIndex == 62 or nIndex == 63 ) then
  105.         return 1
  106.     end
  107.  
  108.     return 0
  109. end
  110.  
  111. function IsSingleStateButton( nIndex )
  112.     if ( nIndex == 10 or nIndex == 16 or nIndex == 17 ) then
  113.         return 1
  114.     end
  115.  
  116.     if ( nIndex == 61 or nIndex == 62 or nIndex == 63 ) then
  117.         return 1
  118.     end
  119.  
  120.     return 0
  121. end
  122.  
  123. function ProcessButtonsMessage( nIndex )
  124.     local nID = gButtons[ nActivePanel ][ nIndex ]
  125.     if ( nID == -1 ) then
  126.         return
  127.     end
  128.  
  129.     if ( nActivePanel == E_USUAL_BUTTONS ) then
  130.         local temp = IsActiveButton( nID )
  131.         if ( temp ~= 0 ) then
  132.             AddMessage( 65537, 20000 + nID, 1 )    --NEXT_STATE
  133.         else
  134.             if ( nID == 70 or nID == 71 or nID == 72 or nID == 73 ) then
  135.                 AddMessage( 65537, 20000 + nID, 1 )    --NEXT_STATE
  136.             end
  137.         end
  138.         return
  139.     end
  140.  
  141.     if ( nIndex == 12 ) then                        --RETURN
  142.         AddMessage( 65537, 22011, 1 )            --NEXT_STATE
  143.         return
  144.     end
  145.  
  146.     local bSendMessage = 1
  147.     if ( nActivePanel == E_AVIA_BUTTONS ) then
  148.         if ( gActiveAviations[ nIndex ] == 0 ) then
  149.             --this avia unit is disabled
  150.             --clear active avia button
  151.             if ( nLastActiveButton ~= 0 ) then
  152.                 AddMessage( 65536, nLastActiveButton, 0 )    --SET_STATE
  153.                 nLastActiveButton = 0
  154.             end
  155.  
  156.             bSendMessage = 0
  157.         end
  158.     end
  159.  
  160.     if ( nActivePanel == E_FORMATION_BUTTONS ) then
  161.         if ( nIndex == 4 ) then
  162.             nIndex = 2
  163.         else
  164.             if ( nIndex == 2 ) then
  165.                 nIndex = 4
  166.             end
  167.         end
  168.         if ( gActiveFormations[ nIndex ] == 0 ) then
  169.             --this formation is disabled
  170.             bSendMessage = 0
  171.         end
  172.     end
  173.  
  174.     if ( nActivePanel == E_SHELL_BUTTONS ) then
  175.         if ( gActiveShellTypes[ nIndex ] == 0 ) then
  176.             --this shell type is disabled
  177.             bSendMessage = 0
  178.         end
  179.     end
  180.  
  181.     if ( bSendMessage ~= 0 ) then
  182.         AddMessage( 65537, 20000 + nID, 1 )    --NEXT_STATE
  183.     end
  184. end
  185.  
  186. function HideActivePanel()
  187.     if ( nActivePanel == E_BUILD_BUTTONS ) then
  188.         ShowBuildButtons( 0 )
  189.     end
  190.     if ( nActivePanel == E_MINE_BUTTONS ) then
  191.         ShowMineButtons( 0 )
  192.     end
  193.     if ( nActivePanel == E_FORMATION_BUTTONS ) then
  194.         ShowFormationButtons( 0 )
  195.     end
  196.     if ( nActivePanel == E_AVIA_BUTTONS ) then
  197.         ShowAviaButtons( 0 )
  198.     end
  199.     if ( nActivePanel == E_SHELL_BUTTONS ) then
  200.         ShowShellButtons( 0 )
  201.     end
  202.  
  203. --    nActivePanel = E_USUAL_BUTTONS
  204.     return
  205. end
  206.  
  207. function ShowBuildButtons( bShow )
  208.     if ( bShow ~= 0 ) then
  209.         nActivePanel = E_BUILD_BUTTONS
  210.     else
  211.         nActivePanel = E_USUAL_BUTTONS
  212.     end
  213.  
  214.     AddMessage( 65552, 20023, bShow )
  215.     AddMessage( 65552, 20029, bShow )
  216.     AddMessage( 65552, 20024, bShow )
  217.     AddMessage( 65552, 20028, bShow )
  218.  
  219.     local i = 4
  220.     while ( i < 12 ) do
  221.         AddMessage( 65552, 22000+i, bShow )
  222.         i = i + 1
  223.     end
  224. end
  225.  
  226. function ShowMineButtons( bShow )
  227.     if ( bShow ~= 0 ) then
  228.         nActivePanel = E_MINE_BUTTONS
  229.     else
  230.         nActivePanel = E_USUAL_BUTTONS
  231.     end
  232.  
  233.     AddMessage( 65552, 20020, bShow )
  234.     AddMessage( 65552, 20021, bShow )
  235.  
  236.     local i = 2
  237.     while ( i < 12 ) do
  238.         AddMessage( 65552, 22000+i, bShow )
  239.         i = i + 1
  240.     end
  241. end
  242.  
  243. function ShowFormationButtons( bShow )
  244.     if ( bShow ~= 0 ) then
  245.         nActivePanel = E_FORMATION_BUTTONS
  246.     else
  247.         nActivePanel = E_USUAL_BUTTONS
  248.     end
  249.  
  250.     AddMessage( 65552, 20050, bShow )
  251.     AddMessage( 65552, 20051, bShow )
  252.     AddMessage( 65552, 20052, bShow )
  253.     AddMessage( 65552, 20053, bShow )
  254.     AddMessage( 65552, 20054, bShow )
  255.  
  256.     local i = 5
  257.     while ( i < 12 ) do
  258.         AddMessage( 65552, 22000+i, bShow )
  259.         i = i + 1
  260.     end
  261. end
  262.  
  263. function ShowAviaButtons( bShow )
  264.     if ( bShow ~= 0 ) then
  265.         nActivePanel = E_AVIA_BUTTONS
  266.     else
  267.         nActivePanel = E_USUAL_BUTTONS
  268.     end
  269.  
  270.     AddMessage( 65552, 20032, bShow )        --SHOW WINDOW
  271.     AddMessage( 65552, 20030, bShow )        --SHOW WINDOW
  272.     AddMessage( 65552, 20031, bShow )        --SHOW WINDOW
  273.     AddMessage( 65552, 20035, bShow )        --SHOW WINDOW
  274.     AddMessage( 65552, 20033, bShow )        --SHOW WINDOW
  275.  
  276.     local i = 5
  277.     while ( i < 12 ) do
  278.         AddMessage( 65552, 22000+i, bShow )
  279.         i = i + 1
  280.     end
  281. end
  282.  
  283. function ShowShellButtons( bShow )
  284.     if ( bShow ~= 0 ) then
  285.         nActivePanel = E_SHELL_BUTTONS
  286.     else
  287.         nActivePanel = E_USUAL_BUTTONS
  288.     end
  289.  
  290.     AddMessage( 65552, 20055, bShow )        --SHOW WINDOW
  291. --    AddMessage( 65552, 20056, bShow )        --SHOW WINDOW
  292.     AddMessage( 65552, 20057, bShow )        --SHOW WINDOW
  293.  
  294. --    local i = 3
  295.     local i = 2
  296.     while ( i < 12 ) do
  297.         AddMessage( 65552, 22000+i, bShow )
  298.         i = i + 1
  299.     end
  300. end
  301.  
  302. function LuaProcessMessage( nMessageCode, nFirst, nSecond )
  303.     if ( nMessageCode == 2097664 ) then
  304.         return 0                    --for faster perfomance
  305.     end
  306.     if ( nMessageCode == 1048579 ) then
  307.         return 0                    --for faster perfomance
  308.     end
  309.  
  310.     if ( nMessageCode >= 205 and nMessageCode <= 214 ) then
  311.         --AVIATION DISABLE -- ENABLE
  312. --        OutputValue( "Avia message", nMessageCode )
  313.         local temp = nMessageCode - 205
  314.         if ( temp == 0 or temp == 1 ) then
  315.             gActiveAviations[1] = IsActiveBit( temp + 1, 0 )
  316.             AddMessage( 65568, 20032, gActiveAviations[1] )
  317.         end
  318.         if ( temp == 2 or temp == 3 ) then
  319.             gActiveAviations[2] = IsActiveBit( temp + 1, 0 )
  320.             AddMessage( 65568, 20030, gActiveAviations[2] )
  321.         end
  322.         if ( temp == 4 or temp == 5 ) then
  323.             gActiveAviations[3] = IsActiveBit( temp + 1, 0 )
  324.             AddMessage( 65568, 20031, gActiveAviations[3] )
  325.         end
  326.         if ( temp == 6 or temp == 7 ) then
  327.             gActiveAviations[4] = IsActiveBit( temp + 1, 0 )
  328.             AddMessage( 65568, 20035, gActiveAviations[4] )
  329.         end
  330.         if ( temp == 8 or temp == 9 ) then
  331.             gActiveAviations[5] = IsActiveBit( temp + 1, 0 )
  332.             AddMessage( 65568, 20033, gActiveAviations[5] )
  333.         end
  334.  
  335.         --these messages need to be forwarded to the game
  336.         local nMessage = SetProcessedFlag( nMessageCode )
  337.         AddMessage( nMessage, nFirst, nSecond )
  338.         return 1
  339.     end
  340.  
  341.     if ( nMessageCode == 524 ) then
  342.         --local bCanProcess = IsGameButtonProcessing();
  343. --        if ( bCanProcess ~= 0 ) then 
  344.             --Show aviation buttons
  345.             HideActivePanel()
  346.             ShowAviaButtons( 1 )
  347.             OutputValue( "**** aviation enabled", 1 );
  348. --        end
  349.         return 1
  350.     end
  351.  
  352.     if ( nMessageCode == 525 ) then
  353.         --Show SHELL TYPE buttons
  354.         HideActivePanel()
  355.         ShowShellButtons( 1 )
  356.         return 1
  357.     end
  358.  
  359.     -- process 'change actions set' message
  360.     if ( nMessageCode == 201 ) then
  361.         HideActivePanel()
  362.  
  363.         p1 = 0
  364.         p2 = 0
  365.         p3 = 0
  366.         p4 = 0
  367.  
  368.         --show empty buttons (bottom row of buttons)
  369.         AddMessage( 65552, 22090, 1 )
  370.         AddMessage( 65552, 22091, 1 )
  371.         AddMessage( 65552, 22092, 1 )
  372.         AddMessage( 65552, 22093, 1 )
  373.         gButtons[1][9]  = -1
  374.         gButtons[1][10] = -1
  375.         gButtons[1][11] = -1
  376.         gButtons[1][12] = -1
  377.  
  378.         local i = 1
  379.         while ( i < 32 ) do
  380.             local temp = IsActiveButton( i )
  381.             if ( temp ~= 0 ) then
  382.                 nRes = IsActiveBit( nFirst, i )
  383.  
  384.                 if ( nRes ~= 0 ) then
  385.                     AddMessage( 65568, 20000 + i, 1 )        --ENABLE WINDOW
  386.                     local nRes = IsSingleStateButton( i )
  387.                     if ( nRes == 0 ) then
  388.                         AddMessage( 65536, 20000 + i, 0 )    --SET STATE 0
  389.                     end
  390.                 else
  391.                     AddMessage( 65568, 20000 + i, 0 )        --ENABLE WINDOW (DISABLE)
  392.                 end
  393.             end
  394.             i = i + 1
  395.         end
  396.  
  397.         nRes = IsActiveBit( nFirst, 5 )            --5, UNLOAD
  398.         if ( nRes ~= 0 ) then
  399.             p1 = 40
  400.             AddMessage( 65552, 20005, 1 )
  401.             gButtons[1][9] = 5
  402.         end
  403.  
  404.         nRes = IsActiveBit( nFirst, 13 )        --13, SUPRESSIVE FIRE
  405.         if ( nRes ~= 0 and p1 < 30 ) then
  406.             p1 = 30
  407.             AddMessage( 65552, 20013, 1 )
  408.             gButtons[1][9] = 13
  409.         end
  410.  
  411.         nRes = IsActiveBit( nFirst, 23 )        --23 is BUILD ANTY PERSON
  412.         if ( nRes ~= 0 and p1 < 20 ) then
  413.             p1 = 20
  414.             AddMessage( 65552, 20070, 1 )
  415.             gButtons[1][9] = 70
  416.         end
  417.  
  418.         nRes = IsActiveBit( nFirst, 11 )        --11 is MAKE FORMATION
  419.         if ( nRes ~= 0 and p1 < 10 ) then
  420.             p1 = 10
  421.             AddMessage( 65552, 20072, 1 )
  422.             gButtons[1][9] = 72
  423.         end
  424.  
  425.         nRes = IsActiveBit( nFirst, 12 )        --12, RANGING
  426.         if ( nRes ~= 0 ) then
  427.             p2 = 40
  428.             AddMessage( 65552, 20012, 1 )
  429.             gButtons[1][10] = 12
  430.         end
  431.  
  432.         nRes = IsActiveBit( nFirst, 27 )        --27, RESUPPLY
  433.         if ( nRes ~= 0 and p2 < 30 ) then
  434.             p2 = 30
  435.             AddMessage( 65552, 20027, 1 )
  436.             gButtons[1][10] = 27
  437.         end
  438.  
  439.         nRes = IsActiveBit( nFirst, 26 )        --26, REPAIR
  440.         if ( nRes ~= 0 and p2 < 20 ) then
  441.             p2 = 20
  442.             AddMessage( 65552, 20026, 1 )
  443.             gButtons[1][10] = 26
  444.         end
  445.  
  446.         nRes = IsActiveBit( nFirst, 15 )        --15, CHOOSE FIRE SHELL TYPE
  447.         if ( nRes ~= 0 ) then
  448.             p3 = 40
  449.             AddMessage( 65552, 20073, 1 )
  450.             gButtons[1][11] = 73
  451.         end
  452.  
  453.         nRes = IsActiveBit( nFirst, 20 )        --20 is SET MINE
  454.         if ( nRes ~= 0 and p3 < 20 ) then
  455.             p3 = 20
  456.             AddMessage( 65552, 20071, 1 )
  457.             gButtons[1][11] = 71
  458.         end
  459.  
  460.         nRes = IsActiveBit( nFirst, 22 )        --22, DEMINE
  461.         if ( nRes ~= 0 and p4 < 20 ) then
  462.             p4 = 20
  463.             AddMessage( 65552, 20022, 1 )
  464.             gButtons[1][12] = 22
  465.         end
  466.  
  467.         return 1
  468.     end
  469.  
  470.     if ( nMessageCode == 202 ) then
  471.         i = 0
  472.         while ( i < 32 ) do
  473.             temp = IsActiveButton( i + 32 )
  474.             if ( temp ~= 0 ) then
  475.                 nRes = IsActiveBit( nFirst, i )
  476.                 if ( nRes ~= 0 ) then
  477.                     AddMessage( 65568, 20032 + i, 1 )        --ENABLE WINDOW
  478.                     local nRes = IsSingleStateButton( i + 32 )
  479.                     if ( nRes == 0 ) then
  480.                         AddMessage( 65536, 20032 + i, 0 )    --SET STATE 0
  481.                     end
  482.                 else
  483.                     AddMessage( 65568, 20032 + i, 0 )        --ENABLE WINDOW (DISABLE)
  484.                 end
  485.             else
  486.                 if ( i >= 18 and i <= 22 ) then
  487.                     nRes = IsActiveBit( nFirst, i )
  488.                     if ( nRes ~= 0 ) then
  489.                         gActiveFormations[i - 17] = 1
  490.                         AddMessage( 65568, 20032 + i, 1 )    --ENABLE WINDOW
  491.                     else
  492.                         gActiveFormations[i - 17] = 0
  493.                         AddMessage( 65568, 20032 + i, 0 )    --ENABLE WINDOW (DISABLE)
  494.                     end
  495.                 end
  496.  
  497.                 if ( i >= 23 and i <= 25 ) then
  498.                     nRes = IsActiveBit( nFirst, i )
  499.                     if ( nRes ~= 0 ) then
  500.                         gActiveShellTypes[i - 22] = 1
  501.                         AddMessage( 65568, 20032 + i, 1 )    --ENABLE WINDOW
  502.                     else
  503.                         gActiveShellTypes[i - 22] = 0
  504.                         AddMessage( 65568, 20032 + i, 0 )    --ENABLE WINDOW (DISABLE)
  505.                     end
  506.                 end
  507.             end
  508.  
  509.             i = i + 1
  510.         end
  511.  
  512.         nRes = IsActiveBit( nFirst, 10 )        --42, DEPLOY ARTILLERY
  513.         if ( nRes ~= 0 and p1 < 35 ) then
  514.             p1 = 35
  515.             OutputValue( "++++++++++++Gotcha++++++++++~~~~~+++", 1 );
  516.             AddMessage( 65552, 20042, 1 )
  517.             gButtons[1][9] = 42
  518.         end
  519.  
  520.         nRes = IsActiveBit( nFirst, 2 )            --34, BINOCULARS
  521.         if ( nRes ~= 0 and p2 < 10 ) then
  522.             p2 = 10
  523.             AddMessage( 65552, 20034, 1 )
  524.             gButtons[1][10] = 34
  525.         end
  526.  
  527.         nRes = IsActiveBit( nFirst, 4 )            --36, MOBILIZE (HUMAN RESUPPLY)
  528.         if ( nRes ~= 0 and p3 < 30 ) then
  529.             p3 = 30
  530.             AddMessage( 65552, 20036, 1 )
  531.             gButtons[1][11] = 36
  532.         end
  533.  
  534.         nRes = IsActiveBit( nFirst, 29 )        --61, SQUAD-
  535.         if ( nRes ~= 0 and p3 < 10 ) then
  536.             p3 = 10
  537.             AddMessage( 65552, 20061, 1 )
  538.             gButtons[1][11] = 61
  539.         end
  540.  
  541.         nRes = IsActiveBit( nFirst, 30 )        --62, SQUAD+
  542.         if ( nRes ~= 0 and p3 < 5 ) then
  543.             p3 = 5
  544.             AddMessage( 65552, 20062, 1 )
  545.             gButtons[1][11] = 62
  546.         end
  547.  
  548.         return 1
  549.     end
  550.  
  551.  
  552. --    event come from outside (game)
  553. --    if ( nMessageCode < 64 ) then
  554. --        if ( IsActiveButton( nMessageCode ) ~= 0 ) then
  555. --            AddMessage( 65537, 20000 + nMessageCode, 1 )    --NEXT_STATE
  556. --            return 1
  557. --        end
  558. --        return 0
  559. --    end
  560.  
  561.     if ( nMessageCode >= 4194561 and nMessageCode <= 4194572 ) then
  562.         ProcessButtonsMessage( nMessageCode - 4194560 )
  563.         return 1
  564.     end
  565.  
  566.     if ( nMessageCode > 256 and nMessageCode < 320 ) then
  567.         --Command was processed by the game, we need to clear interface button
  568.         local temp = IsActiveButton( nMessageCode - 256 )
  569.         if ( temp ~= 0 ) then
  570.             local nRes = IsSingleStateButton( nMessageCode - 256 )
  571.             if ( nRes == 0 ) then
  572.                 AddMessage( 65536, 20000 - 256 + nMessageCode, 0 )    --CHANGE_STATE to 0 (clear state)
  573.             end
  574.             return 1
  575.         end
  576.  
  577.         if ( nMessageCode == 23+256 or nMessageCode == 29+256 or nMessageCode == 24+256 or nMessageCode == 28+256 ) then
  578.             if ( nMessageCode - 256 == nLastActiveButton - 20000 ) then
  579.                 --BUILD ACTION DONE
  580.                 nLastActiveButton = 0
  581.                 AddMessage( 65536, 20000 - 256 + nMessageCode, 0 )    --CHANGE_STATE to 0 (clear state)
  582.                 ShowBuildButtons( 0 )
  583.             end
  584.  
  585.             return 1
  586.         end
  587.  
  588.         if ( nMessageCode == 20+256 or nMessageCode == 21+256 ) then
  589.             if ( nMessageCode - 256 == nLastActiveButton - 20000 ) then
  590.                 --MINE WAS PLACED
  591.                 nLastActiveButton = 0
  592.                 AddMessage( 65536, 20000 - 256 + nMessageCode, 0 )    --CHANGE_STATE to 0 (clear state)
  593.                 ShowMineButtons( 0 )
  594.             end
  595.  
  596.             return 1
  597.         end
  598.  
  599.         if ( (nMessageCode >= 30+256 and nMessageCode <= 33+256) or nMessageCode == 35+256 ) then
  600.             if ( nMessageCode - 256 == nLastActiveButton - 20000 ) then
  601.                 --AVIA WAS CALLED
  602.                 nLastActiveButton = 0
  603.                 AddMessage( 65536, 20000 - 256 + nMessageCode, 0 )    --CHANGE_STATE to 0 (clear state)
  604.                 ShowAviaButtons( 0 )
  605.             end
  606.  
  607.             return 1
  608.         end
  609.  
  610.         return 0
  611.     end
  612.     
  613.     -- in-UI messages about state changing
  614.     if ( nMessageCode == 536936448 and nFirst > 20000 and nFirst < 20064 ) then    --NOTIFY_CHANGE_STATE
  615.         local nRes = IsSingleStateButton( nFirst - 20000 )
  616.         if ( nRes ~= 0 ) then
  617.             --these buttons have only one state
  618.             if ( nLastActiveButton ~= 0 ) then
  619.                 AddMessage( 65536, nLastActiveButton, 0 )    --SET_STATE
  620.                 nLastActiveButton = 0
  621.             else
  622.                 AddMessage( 65616, nFirst, 100 );
  623.             end
  624.  
  625.             local nNewMessageCode = SetProcessedFlag( nFirst - 20000 )
  626.             AddMessage( nNewMessageCode, 0, 0 )
  627.             return 1
  628.         end
  629.  
  630.         if ( nFirst - 20000 >= 50 and nFirst - 20000 <= 54 ) then            --FORMATIONS
  631.             --these buttons have only one state
  632.             if ( nLastActiveButton ~= 0 ) then
  633.                 AddMessage( 65536, nLastActiveButton, 0 )    --SET_STATE
  634.                 nLastActiveButton = 0
  635.             end
  636.  
  637.             local nNewMessageCode = SetProcessedFlag( nFirst - 20000 )
  638.             AddMessage( nNewMessageCode, 0, 0 )
  639.  
  640.             ShowFormationButtons( 0 )
  641.             return 1
  642.         end
  643.  
  644.         if ( nFirst - 20000 >= 55 and nFirst - 20000 <= 57 ) then            --CHOOSE SHELLS TYPE
  645.             --these buttons have only one state
  646.             if ( nLastActiveButton ~= 0 ) then
  647.                 AddMessage( 65536, nLastActiveButton, 0 )    --SET_STATE
  648.                 nLastActiveButton = 0
  649.             end
  650.  
  651.             local nNewMessageCode = SetProcessedFlag( nFirst - 20000 )
  652.             AddMessage( nNewMessageCode, 0, 0 )
  653.  
  654.             ShowShellButtons( 0 )
  655.             return 1
  656.         end
  657.  
  658.         if ( nSecond == 1 ) then
  659.             if ( nLastActiveButton ~= 0 and nLastActiveButton ~=  nFirst ) then  -- this button isn't active button 
  660.                 OutputValue("don't allow to actovate button", nFirst );
  661.                 OutputValue("because current active is ", nLastActiveButton );
  662.                 AddMessage( 65536, nLastActiveButton, 0 )    --SET_STATE
  663.             end
  664.             nLastActiveButton = nFirst
  665.  
  666.             local nNewMessageCode = SetProcessedFlag( nFirst - 20000 )
  667.             AddMessage( nNewMessageCode, 0, 0 )
  668.  
  669.             return 1
  670.         end
  671.         if ( nSecond == 0 ) then
  672.             if ( nLastActiveButton == nFirst ) then
  673.                 OutputValue("deactivate button", nFirst );
  674.                 nLastActiveButton = 0
  675.             end
  676.  
  677.             local nNewMessageCode = SetProcessedFlag( nFirst + 256 - 20000 )    --RESET_ACTION_xx
  678.             AddMessage( nNewMessageCode, 0, 0 )
  679.             return 1
  680.         end
  681.     end
  682.  
  683. --    if ( nMessageCode == 536936448 and nFirst >= 20080 and nFirst <= 20083 ) then    --CHOOSE FORMATION
  684. --        local nNewMessageCode = SetProcessedFlag( 11 )
  685. --        AddMessage( nNewMessageCode, nFirst - 20080, 0 )
  686. --        return 1
  687. --    end
  688.  
  689.     if ( nMessageCode == 536936448 and nFirst == 22011 ) then    --RETURN
  690.         HideActivePanel()
  691.         if ( nLastActiveButton ~= 0 ) then
  692.             AddMessage( 65536, nLastActiveButton, 0 )    --CHANGE_STATE to 0 (clear state)
  693.             nLastActiveButton = 0
  694.         end
  695.  
  696.         return 1
  697.     end
  698.  
  699.     if ( nMessageCode == 536936448 and nFirst == 20070 ) then    --BUILD
  700.         HideActivePanel()
  701.         ShowBuildButtons( 1 )
  702.         return 1
  703.     end
  704.  
  705.     if ( nMessageCode == 536936448 and nFirst == 20071 ) then    --SET MINE
  706.         HideActivePanel()
  707.         ShowMineButtons( 1 )
  708.  
  709.         return 1
  710.     end
  711.  
  712.     if ( nMessageCode == 536936448 and nFirst == 20072 ) then    --CHOOSE FORMATION
  713.         HideActivePanel()
  714.         ShowFormationButtons( 1 )
  715.  
  716.         return 1
  717.     end
  718.  
  719.     if ( nMessageCode == 536936448 and nFirst == 20073 ) then    --SHELL TYPE
  720.         HideActivePanel()
  721.         ShowShellButtons( 1 )
  722.  
  723.         return 1
  724.     end
  725.  
  726.     if ( nMessageCode == 536936448 and nFirst >= 22030 and nFirst <= 22035 and nFirst ~= 22034 ) then
  727.         --diable avia button pressed
  728.         --clear active avia button
  729.         if ( nLastActiveButton ~= 0 ) then
  730.             AddMessage( 65536, nLastActiveButton, 0 )    --SET_STATE
  731.             nLastActiveButton = 0
  732.         end
  733.         return 1
  734.     end
  735.  
  736.     return 0
  737. end
  738.